--
-- Author: ping.wang
-- Date: 2019-05-05 17:42:07
--
-- NewRankGuildDetailView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.NewGuildDetailScene

function ClassRef:init()
	self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)
    
  
    self._ui.btn_join:addClickEventListener(function()
        --申请入会的命令
        if self._data then
            local guildModel = app:getInst("NewguildModel")
            if cc.isAlive(guildModel) then
                guildModel:reqApplyGuild(self._data:getGuildId())
            end
            -- executeFunc(self._onOperate, "applyGuild",self._data:getGuildId())
        end
    end)

    local guildInfo = self._data
    local isJoinBtnEnable = not UD:isInGuild()
    if isJoinBtnEnable and guildInfo.getServerIndex then
        -- 判断是否是本服公会
        isJoinBtnEnable = app.session:getZoneId() == guildInfo:getServerIndex()
    end
      --若自己已有公会 按钮不能按下且灰色
    if isJoinBtnEnable then
        display.setBtnTouchEnable(self._ui.btn_join,true)
    else
        display.setBtnTouchEnable(self._ui.btn_join,false)
    end

    self._ui.Panel_1:findChild("data"):setString(guildInfo:getGuildName())
    self._ui.Panel_2:findChild("data"):setString(guildInfo:getGuildLeaderName())
    self._ui.Panel_3:findChild("data"):setString(guildInfo:getGuildLv())
    self._ui.Panel_4:findChild("data"):setString(guildInfo:getGuildMemberNum())

    local totalCombatPw = guildInfo:getGuildTotalCombatPw()
    if totalCombatPw > 10000 then
        self._ui.Panel_5:findChild("data"):setString(string.format("%d%s",math.floor(totalCombatPw/10000),L("damageunit1")))
    else
        self._ui.Panel_5:findChild("data"):setString(totalCombatPw)
    end

    local highestCombatPowr = guildInfo:getHighestCombatPowr()
    if highestCombatPowr > 10000 then
        self._ui.Panel_6:findChild("data"):setString(string.format("%d%s",math.floor(highestCombatPowr/10000),L("damageunit1")))
    else
        self._ui.Panel_6:findChild("data"):setString(highestCombatPowr)
    end


    self._ui.Panel_7:findChild("data"):setString(guildInfo:getTotalContribution())
    self._ui.Panel_8:findChild("data"):setString(guildInfo:getTotalProsperity())
    local desc = guildInfo:getGuildDesc()
    if desc and #desc > 0 then
        self._ui.Panel_content:findChild("text"):setString(desc)
    else
        self._ui.Panel_content:findChild("text"):setString(L("guild_default_notice"))
    end
end

return ClassRef
